﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BE;
using System.IO;
using System.Media;

namespace DHLAppMovil
{
    public partial class FrmAuto : Form
    {
        public static Vehiculo vehiculo;
        public FrmAuto()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void lblNombre_ParentChanged(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click_1(object sender, EventArgs e)
        {

        }

        private void FrmAuto_Load(object sender, EventArgs e)
        {
            if (FrmApp.persona != null)
            {
                button1.Visible = true;
                label1.Visible = false;
                lblPersona.Visible = true;
                lblPersona.Text = FrmApp.persona.Nombre;
                
            }
            else 
            {
                button1.Visible = false;
                label1.Visible = true;
                lblPersona.Visible = false;
                //lblPersona.Text = "NO SE HA LEIDO A NINGÚN PERSONAL";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Se guarda en la base de datos
            VehiculoxPersona vxh = new VehiculoxPersona();
            vxh.IpkCode = FrmApp.persona.IpkCode;
            vxh.CodVehiculoString = vehiculo.CodVehiculoString;
            vxh.CodPersonaString = FrmApp.persona.Codigo;
            vxh.Fecha = DateTime.Now;
            vxh.PuertaAcceso = "TERMINAL HANDHELD";
            DatabaseContext.Current.Client.Store(vxh);
            DatabaseContext.Current.Client.Commit();
            FrmApp.persona = null;
            vehiculo = null;
            this.Close();
            Stream audioStream = new MemoryStream(Properties.Resources.confirm);

            SoundPlayer player = new SoundPlayer(audioStream);
            player.Play();


        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}